/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package cn.knet.sp.ncrm.modules.customer.potentialcustomer.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import cn.knet.sp.ncrm.common.config.Global;
import cn.knet.sp.ncrm.common.persistence.Page;
import cn.knet.sp.ncrm.common.web.BaseController;
import cn.knet.sp.ncrm.common.utils.StringUtils;
import cn.knet.sp.ncrm.modules.customer.potentialcustomer.entity.PotentialCustomerAddinfo;
import cn.knet.sp.ncrm.modules.customer.potentialcustomer.service.PotentialCustomerAddinfoService;

/**
 * 潜在客户附加表Controller
 * @author gehaiyang
 * @version 2015-08-24
 */
@Controller
@RequestMapping(value = "${adminPath}/customer/potentialCustomerAddinfo")
public class PotentialCustomerAddinfoController extends BaseController {

	@Autowired
	private PotentialCustomerAddinfoService potentialCustomerAddinfoService;
	
	@ModelAttribute
	public PotentialCustomerAddinfo get(@RequestParam(required=false) String id) {
		PotentialCustomerAddinfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = potentialCustomerAddinfoService.get(id);
		}
		if (entity == null){
			entity = new PotentialCustomerAddinfo();
		}
		return entity;
	}
	
	@RequiresPermissions("customer:potentialCustomerAddinfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(PotentialCustomerAddinfo potentialCustomerAddinfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<PotentialCustomerAddinfo> page = potentialCustomerAddinfoService.findPage(new Page<PotentialCustomerAddinfo>(request, response), potentialCustomerAddinfo); 
		model.addAttribute("page", page);
		return "modules/customer/potentialcustomer/potentialCustomerAddinfoList";
	}

	@RequiresPermissions("customer:potentialCustomerAddinfo:view")
	@RequestMapping(value = "form")
	public String form(PotentialCustomerAddinfo potentialCustomerAddinfo, Model model) {
		model.addAttribute("potentialCustomerAddinfo", potentialCustomerAddinfo);
		return "modules/customer/potentialcustomer/potentialCustomerAddinfoForm";
	}

	@RequiresPermissions("customer:potentialCustomerAddinfo:edit")
	@RequestMapping(value = "save")
	public String save(PotentialCustomerAddinfo potentialCustomerAddinfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, potentialCustomerAddinfo)){
			return form(potentialCustomerAddinfo, model);
		}
		potentialCustomerAddinfoService.save(potentialCustomerAddinfo);
		addMessage(redirectAttributes, "保存潜在客户成功");
		return "redirect:"+Global.getAdminPath()+"/customer/potentialcustomer/potentialCustomerAddinfo/?repage";
	}
	
	@RequiresPermissions("customer:potentialCustomerAddinfo:edit")
	@RequestMapping(value = "delete")
	public String delete(PotentialCustomerAddinfo potentialCustomerAddinfo, RedirectAttributes redirectAttributes) {
		potentialCustomerAddinfoService.delete(potentialCustomerAddinfo);
		addMessage(redirectAttributes, "删除潜在客户成功");
		return "redirect:"+Global.getAdminPath()+"/customer/potentialcustomer/potentialCustomerAddinfo/?repage";
	}

	@RequiresPermissions("customer:potentialCustomerAddinfo:view")
	@RequestMapping(value = "listAjaxData")
	@ResponseBody
	public Page<PotentialCustomerAddinfo> listAjaxData(PotentialCustomerAddinfo potentialCustomerAddinfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<PotentialCustomerAddinfo> page = potentialCustomerAddinfoService.findPage(new Page<PotentialCustomerAddinfo>(request, response), potentialCustomerAddinfo);
		return page;
	}

}